Skip to content

Created Android scoped storage migration method #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

EvanBacon
Copy link
Contributor

@EvanBacon EvanBacon commented Mar 13, 2021

Summary

Expo users who publish an app with expo build:android will use a database file like RKStorage-scoped-experience- <encoded-project-slug> when they eject, the
database file will be RKStorage, this effectively prevents many users from being able to eject expo/expo#8220 and use this package.

This PR introduces parity for an iOS feature that migrates the database directory.

  1. Check to see if RKStorage file exists (if not bail out).
  2. Query all files in the database directory starting with RKStorage-scoped-experience-
  3. Get the most recently modified file to migrate. This is useful because users who change their slug and republish may have multiple database files and they'll want to use the most recent one.
  4. Copy the contents of this file to RKStorage
  5. Delete all of the scoped database files. This creates parity with iOS.

Test Plan

Testing this feature is a little involved.

Managed -> Bare

  1. Delete the app -- effectively deleting all of it's data and the RKStorage file.
  2. Comment out the line AsyncStorageMigration.migrate(reactContext);
  3. Change "RKStorage" to something like RKStorage-scoped-experience-foobar-1
  4. Build the app, make a few modifications.
  5. Repeat the last two steps with a new storage name (RKStorage-scoped-experience-foobar-2) -- This is to test that the most recent slug gets used.
  6. Uncomment the line AsyncStorageMigration.migrate(reactContext); and change the database name back to RKStorage.
  7. Build the app, you'll notice the logs print out info about the migration (ScopedStorageMigration log tag). The AsyncStorage in-app should have changed to match the most recent modifications from RKStorage-scoped-experience-foobar-2.
  8. Reload the app, you should see no longs related to the migration.

Bare only

  1. Delete the app -- effectively deleting all of it's data and the RKStorage file.
  2. Build the app, you should see a log "No scoped database found" -- This is what users who run AsyncStorage for the first time without ever using Expo will see.
  3. Reload the app and there should be no logs related to the migration.

@EvanBacon EvanBacon added the enhancement New feature or request label Mar 13, 2021
@EvanBacon EvanBacon requested a review from krizzu March 13, 2021 04:08
@EvanBacon EvanBacon marked this pull request as ready for review March 13, 2021 05:01
Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one Evan 👍 I just left few comments to make it bit more explicit that this migration is related to Expo.

@EvanBacon EvanBacon requested a review from krizzu March 21, 2021 23:49
@krizzu krizzu requested a review from tido64 March 22, 2021 09:19
Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍
@tido64 mind having a look as well?

Copy link
Member

@tido64 tido64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. Just a couple of questions to educate myself 😄

@EvanBacon EvanBacon merged commit a21cb9f into react-native-async-storage:master Apr 2, 2021
@EvanBacon EvanBacon deleted the @evanbacon/android/expo-migration-script branch April 2, 2021 00:01
@brentvatne
Copy link
Contributor

thanks a lot for reviewing, @krizzu and @tido64!

@krizzu
Copy link
Member

krizzu commented Apr 2, 2021

🎉 This PR is included in version 1.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@krizzu krizzu added the released label Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants